﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProcessManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProcessManagement.ProcessParameterVMs
{
    public partial class ProcessParameterListVM : BasePagedListVM<ProcessParameter_View, ProcessParameterSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProcessParameter_View>> InitGridHeader()
        {
            return new List<GridColumn<ProcessParameter_View>>{
                
                this.MakeGridHeader(x => x.ProcessParameter_Route).SetTitle(@Localizer["Page.工艺路线"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_Op).SetTitle(@Localizer["Page.工序"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_TagId).SetTitle(@Localizer["Page.变量"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_TagName).SetTitle(@Localizer["Page.变量名称"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_SetValue).SetTitle(@Localizer["Page.设定值"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_Precision).SetTitle(@Localizer["Page.精度"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_ParameterName).SetTitle(@Localizer["Page.参数名称"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_DataType).SetTitle(@Localizer["Page.数据类型"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProcessParameter_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProcessParameter_View> GetSearchQuery()
        {
            var query = DC.Set<ProcessParameter>()
                
                .CheckEqual(Searcher.RouteId, x=>x.RouteId)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckEqual(Searcher.TagId, x=>x.TagId)
                .CheckContain(Searcher.TagName, x=>x.TagName)
                .CheckContain(Searcher.SetValue, x=>x.SetValue)
                .CheckEqual(Searcher.Precision, x=>x.Precision)
                .CheckContain(Searcher.ParameterName, x=>x.ParameterName)
                .CheckEqual(Searcher.DataType, x=>x.DataType)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProcessParameter_View
                {
				    ID = x.ID,
                    
                    ProcessParameter_Route = x.Op.Routie.RoutingCode,
                    ProcessParameter_Op = x.Op.OpCode,
                    ProcessParameter_TagId = x.TagId,
                    ProcessParameter_TagName = x.Tag.TagName,
                    ProcessParameter_SetValue = x.SetValue,
                    ProcessParameter_Precision = x.Precision,
                    ProcessParameter_ParameterName = x.ParameterName,
                    ProcessParameter_DataType = x.DataType,
                    ProcessParameter_Active = x.Active,
                    ProcessParameter_CreateTime = x.CreateTime,
                    ProcessParameter_UpdateTime = x.UpdateTime,
                    ProcessParameter_CreateBy = x.CreateBy,
                    ProcessParameter_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProcessParameter_View: ProcessParameter
    {
        
        public string ProcessParameter_Route { get; set; }
        public string ProcessParameter_Op { get; set; }
        public long? ProcessParameter_TagId { get; set; }
        public string ProcessParameter_TagName { get; set; }
        public string ProcessParameter_SetValue { get; set; }
        public int? ProcessParameter_Precision { get; set; }
        public string ProcessParameter_ParameterName { get; set; }
        public TagDataTypeEnum? ProcessParameter_DataType { get; set; }
        public bool? ProcessParameter_Active { get; set; }
        public DateTime? ProcessParameter_CreateTime { get; set; }
        public DateTime? ProcessParameter_UpdateTime { get; set; }
        public string ProcessParameter_CreateBy { get; set; }
        public string ProcessParameter_UpdateBy { get; set; }

    }

}